package com.lagou.rpc.consumer;

import com.lagou.rpc.consumer.zk.ConsumerZk;
import com.lagou.rpc.consumer.zk.ReportThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * SpringBoot启动类
 */
@SpringBootApplication
public class ClientBootStrap implements CommandLineRunner {

    @Autowired
    private ConsumerZk consumerZk;

    public static void main(String[] args) {
        SpringApplication.run(ClientBootStrap.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // 启动zk客户端并获取注册的服务端
        consumerZk.connect();
        // 创建线程池，启动定时上报线程
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.submit(new ReportThread(consumerZk.getZkClient()));
    }
}
